<!DOCTYPE html>
<html>
<head>
  <title>Staggered loops | anime.js</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:title" content="anime.js">
  <meta property="og:url" content="http://animejs.com">
  <meta property="og:description" content="Javascript Animation Engine">
  <meta property="og:image" content="http://animejs.com/documentation/assets/img/icons/og.png">
  <meta name="twitter:card" content="summary">
  <meta name="twitter:title" content="anime.js">
  <meta name="twitter:site" content="@juliangarnier">
  <meta name="twitter:description" content="Javascript Animation Engine">
  <meta name="twitter:image" content="http://animejs.com/documentation/assets/img/icons/twitter.png">
  <link rel="apple-touch-icon-precomposed" href="../assets/img/icons/apple-touch-icon.png">
  <link rel="icon" type="image/png" href="../assets/img/icons/favicon.png">
  <link href="../assets/css/anime.css" rel="stylesheet">
  <script src="../../anime.js"></script>
  <!-- <script src="../assets/js/anime.2.1.0.js"></script> -->
  <!-- <script src="../assets/js/anime.2.0.2.js"></script> -->
  <!-- <script src="../assets/js/anime.1.3.js"></script> -->
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100vh;
    }

    .wrapper {
      position: absolute;
      width: 100%;
      height: 100vh;
      overflow: hidden;
    }

    .el {
      position: absolute;
      border-radius: 50%;
      top: 50%;
      left: 50%;
      border: 2px solid currentColor;
      /*background-color: currentColor;*/
    }
  </style>
</head>
<body>
  <div class="wrapper"></div>
  <script>

    const wrapperEl = document.querySelector('.wrapper');
    const numberOfEls = 72;
    const duration = 6000;
    const delay = duration / numberOfEls;
    const gap = 10;

    let tl = anime.timeline({
      duration: delay / 2,
      complete: function() { tl.restart(); }
    });

    function createEl(i) {
      let el = document.createElement('div');
      const rotate = (360 / numberOfEls) * i;
      const translateY = -(numberOfEls - i) * .5;
      const hue = Math.round(180 / numberOfEls * i);
      const diameter = gap + (i * gap);
      const scale = (diameter + gap) / diameter;
      el.classList.add('el');
      el.style.zIndex = numberOfEls - i;
      el.style.width = diameter + 'px';
      el.style.height = diameter + 'px';
      el.style.marginTop = -(diameter / 2) + 'px';
      el.style.marginLeft = -(diameter / 2) + 'px';
      el.style.opacity = 0;
      // el.style.color = 'hsl(' + hue + ', 10%, 10%)';
      tl.add({
        begin: function() {
          anime({
            targets: el,
            opacity: [0, 1],
            color: ['hsl(' + hue + ', 10%, 10%)', 'hsl(' + hue + ', 50%, 50%)'],
            translateY: [0, translateY],
            rotate: [0, 90],
            borderRadius: {
              value: ['30%', '50%'],
              easing: 'easeInOutQuad'
            },
            easing: 'easeInOutSine',
            direction: 'alternate',
            duration: duration / 4
          });
        }
      });
      wrapperEl.appendChild(el);
    };

    for (let i = 0; i < numberOfEls; i++) createEl(i);

  </script>
  <script src="../assets/js/stats.js"></script>
</body>
</html>
